﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Drawing;
using System.Text;
using System.Windows.Forms;

namespace TripleCComiC
{
    public partial class Form1
    {
        private enum SizeMode : int
        {
            Original = 0,
            FitWidth,
            FitHeigth
        }
        private string _currentPath =
            Environment.GetFolderPath(Environment.SpecialFolder.MyComputer);
        public string CurrentPath
        {
            get
            {
                return _currentPath;
            }
            set
            {
                LoadFolder(value);
            }
        }
        private string[] _files = { };
        //private Color[] _fileColors = { };
        private Dictionary<int, Image> _imageCache = new Dictionary<int, Image>();
        private int _imageNumNow = 0;
        public int ImageNumNow
        {
            get { return _imageNumNow; }
            set
            {
                if (value < 0)
                {
                    PlayerStatus = PlayMode.Pause;
                    _imageNumNow = 0;
                }
                else if (value >= _files.Length)
                {
                    PlayerStatus = PlayMode.Pause;
                    _imageNumNow = _files.Length - 1;
                }
                else
                {
                    _imageNumNow = value;
                }
            }
        }
        private int _AnywhereDoor = 0;
        private int _distanceX = 0;
        private int _distanceY = 0;
        private int _imageTop = 0;
        private int _imageLeft = 0;
        private bool _imageDrag = false;
        private Point _imageMouse;
        private double _ratioX = 0.22;
        private double _ratioY = 0.22;
        private double _ratioZoom = 1.0;
        private double _perZoom = 2.0;
        private bool _rightFlip = true;
        private bool _cursorHide = false;
        public bool CursorHide
        {
            get
            {
                return _cursorHide;
            }
            set
            {
                if (_cursorHide != value)
                {
                    _cursorHide = value;
                    if (value)
                    {
                        Cursor.Hide();
                    }
                    else
                    {
                        Cursor.Show();
                    }
                }
            }
        }
        private SizeMode _sizeMode = SizeMode.FitWidth;
        public Dictionary<string, string> LangDict = new Dictionary<string, string>();

        //
        // Video Player
        //
        public enum PlayMode
        {
            Pause,
            Play,
            Rewind,
            Reverse
        }
        private bool _scrolling = false;
        private double _rewindRatio = 1.0;
        private Point _mouseP;
        private HighResTimer _timerPlay = new HighResTimer();
        private HighResTimer _timerReverse = new HighResTimer();
        private Dictionary<Point, int>[] _pointVSTime;
        private PlayMode _playerStatus = PlayMode.Pause;
        public PlayMode PlayerStatus
        {
            get
            {
                return _playerStatus;
            }
            set
            {
                if(_playerStatus != value || value == PlayMode.Rewind)
                {
                    switch (_playerStatus)
                    {
                        case PlayMode.Reverse:
                            _timerReverse.Stop();
                            break;
                        case PlayMode.Play:
                            if (value != PlayMode.Rewind)
                            {
                                _timerPlay.Stop();
                            }
                            break;
                        case PlayMode.Rewind:
                            if (value != PlayMode.Rewind && value != PlayMode.Play)
                            {
                                _timerPlay.Stop();
                            }
                            break;
                    }
                    switch(value)
                    {
                        case PlayMode.Pause:
                            lbl_Status.Text = value.ToString();
                            btn_Pause.Visible = false;
                            break;
                        case PlayMode.Reverse:
                            _rewindRatio = 1.0;
                            _timerReverse.Interval = Convert.ToInt32(1000.0 / uiSetting.FPS);
                            _timerReverse.Start();
                            lbl_Status.Text = value.ToString() + "\nFPS:" + uiSetting.FPS;
                            btn_Pause.Visible = true;
                            break;
                        case PlayMode.Play:
                            _rewindRatio = 1.0;
                            _timerPlay.Interval = Convert.ToInt32(1000.0 / uiSetting.FPS);
                            _timerPlay.Start();
                            lbl_Status.Text = value.ToString() + "\nFPS:" + uiSetting.FPS;
                            btn_Pause.Visible = true;
                            break;
                        case PlayMode.Rewind:
                            _timerPlay.Interval = Convert.ToInt32(1000.0 / uiSetting.FPS / _rewindRatio);
                            _timerPlay.Start();
                            lbl_Status.Text = value.ToString() + "\nFPS:" + (_rewindRatio * uiSetting.FPS);
                            btn_Pause.Visible = true;
                            break;
                    }
                    _playerStatus = value;
                }
            }
        }
        private PlayMode _prePlayerStatus = PlayMode.Pause;
        private BackgroundWorker statusTimer;
    }

    public partial class Browser : Form
    {
        private Form1 _mainForm;
        private string[] _dirs = { };
        private string[] _files = { };
        private BackgroundWorker _workerLoadImage;
        private int _itemCount = 0; // For bug tracing.
    }
}
